home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI676.ASC < prev    next >
Text File  |  1992-02-28  |  6KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Turbo Pascal                           NUMBER  :  676
  9.   VERSION  :  6.0
  10.        OS  :  MS/PC DOS
  11.      DATE  :  February 28, 1992                        PAGE  :  1/5
  12.  
  13.     TITLE  :  Desktop Save State Using Streams
  14.  
  15.  
  16.  
  17.  
  18.   {
  19.  
  20.   This program example demonstrates how to save your
  21.   desktop using a stream.  It will give you the ability
  22.   to insert windows on the desktop and save the current
  23.   state in a .DSK file and load them from the file to
  24.   restore its state.  Streams REQUIRE registration of
  25.   descendant object types.  Turbo Pascal will check that
  26.   all objects in the stream have been registered and
  27.   produce a compiler error otherwise.
  28.  
  29.   }
  30.  
  31.   Program Simple_Stream;
  32.  
  33.   Uses Objects, Drivers, Views, Menus, App;
  34.  
  35.   Type
  36.     PMyApp = ^MyApp;
  37.     MyApp = Object(TApplication)
  38.        Constructor Init;
  39.        Procedure InitStatusLine; Virtual;
  40.        Procedure InitMenuBar; Virtual;
  41.        Procedure HandleEvent(var Event: TEvent); Virtual;
  42.        Procedure NewWindow;
  43.        Destructor Done; Virtual;
  44.     End;
  45.  
  46.     PMyWindow = ^TMyWindow;
  47.     TMyWindow = Object(TWindow)
  48.        Constructor Init(Bounds: TRect; WinTitle: String; WindowNo:
  49.   Word);
  50.     End;
  51.  
  52.     PMyDeskTop = ^TMyDeskTop;
  53.     TMyDeskTop = object(TDeskTop)
  54.        Windw: PMyWindow;
  55.        Constructor Load(var S: TBufStream);
  56.        Procedure Store(var S: TBufStream); Virtual;
  57.     End;
  58.  
  59.   Const
  60.     cmNewWin   = 101;
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Turbo Pascal                           NUMBER  :  676
  75.   VERSION  :  6.0
  76.        OS  :  MS/PC DOS
  77.      DATE  :  February 28, 1992                        PAGE  :  2/5
  78.  
  79.     TITLE  :  Desktop Save State Using Streams
  80.  
  81.  
  82.  
  83.  
  84.     cmSaveDesk = 102;
  85.     cmLoadDesk = 103;
  86.  
  87.     RMyDeskTop: TStreamRec = (
  88.        ObjType : 1001;
  89.        VmtLink : Ofs(TypeOf(TMyDeskTop)^);
  90.        Load    : @TMyDeskTop.Load;
  91.        Store   : @TMyDeskTop.Store
  92.     );
  93.  
  94.     RMyWindow: TStreamRec = (
  95.        ObjType : 1002;
  96.        VmtLink : Ofs(TypeOf(TMyWindow)^);
  97.        Load    : @TMyWindow.Load;
  98.        Store   : @TMyWindow.Store
  99.     );
  100.  
  101.   Procedure SaveDeskStream;
  102.   Var
  103.     SaveFile:TBufStream;
  104.   Begin
  105.     SaveFile.Init('Rdesk.dsk',stCreate,1024);
  106.     SaveFile.Put(DeskTop);
  107.     If Savefile.Status <>0 then
  108.       write('Bad Save', Savefile.Status);
  109.     SaveFile.Done;
  110.   End;
  111.  
  112.   Procedure LoadDeskStream;
  113.   Var
  114.     SaveFile:TBufStream;
  115.   Begin
  116.     SaveFile.Init('Rdesk.dsk',stOpen,1024);
  117.     DeskTop^.Insert(PMyDeskTop(SaveFile.Get));
  118.     If Savefile.Status <>0 then
  119.       write('Bad Load',Savefile.Status)
  120.     else
  121.       DeskTop^.ReDraw;
  122.     SaveFile.Done;
  123.   End;
  124.  
  125.   { ** MyApp **}
  126.   Constructor MyApp.Init;
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Turbo Pascal                           NUMBER  :  676
  141.   VERSION  :  6.0
  142.        OS  :  MS/PC DOS
  143.      DATE  :  February 28, 1992                        PAGE  :  3/5
  144.  
  145.     TITLE  :  Desktop Save State Using Streams
  146.  
  147.  
  148.  
  149.  
  150.   Begin
  151.     TApplication.Init;
  152.     RegisterType(RMyDesktop);
  153.     RegisterType(RDesktop);
  154.     RegisterType(Rwindow);
  155.     RegisterType(RMywindow);
  156.     RegisterType(RFrame);
  157.     RegisterType(RMenuBar);
  158.     RegisterType(RStatusLine);
  159.     RegisterType(RBackground);
  160.   End;
  161.  
  162.   Destructor MyApp.Done;
  163.   Begin
  164.     TApplication.Done;
  165.   End;
  166.  
  167.   Procedure MyApp.InitMenuBar;
  168.   Var
  169.     R: TRect;
  170.   Begin
  171.     GetExtent(R);
  172.     R.B.Y := R.A.Y + 1;
  173.     MenuBar := New(PMenuBar, Init(R, NewMenu(
  174.       NewSubMenu('~F~ile', hcNoContext, NewMenu(
  175.       NewItem('~N~ew', 'F4', kbF4, cmNewWin, hcNoContext,
  176.       NewLine(
  177.          NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  178.          Nil)))),
  179.       NewSubMenu('~D~eskTop', hcNoContext, NewMenu(
  180.          NewItem('~S~ave Desktop','',kbF2,cmSaveDesk,hcNoContext,
  181.          NewItem('~L~oad Desktop','',kbF3,cmLoadDesk,hcNoContext,
  182.       nil))),nil)))));
  183.   End;
  184.  
  185.   Procedure MyApp.InitStatusLine;
  186.   Var
  187.     R: TRect;
  188.   Begin
  189.     GetExtent(R);
  190.     R.A.Y := R.B.Y - 1;
  191.     StatusLine := New(PStatusLine, Init(R,
  192.     NewStatusDef(0, $FFFF,
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Turbo Pascal                           NUMBER  :  676
  207.   VERSION  :  6.0
  208.        OS  :  MS/PC DOS
  209.      DATE  :  February 28, 1992                        PAGE  :  4/5
  210.  
  211.     TITLE  :  Desktop Save State Using Streams
  212.  
  213.  
  214.  
  215.  
  216.       NewStatusKey('', kbF10, cmMenu,
  217.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  218.       NewStatusKey('~F4~ New', kbF4, cmNewWin,
  219.       NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  220.       nil)))),
  221.     nil)));
  222.   End;
  223.  
  224.   Procedure MyApp.HandleEvent(var Event: TEvent);
  225.   Begin
  226.     TApplication.HandleEvent(Event);
  227.     if Event.What = evCommand then
  228.       Begin
  229.         Case Event.Command of
  230.           cmNewWin: NewWindow;
  231.           cmSaveDesk: SaveDeskStream;
  232.           cmLoadDesk: LoadDeskStream;
  233.         else
  234.           Exit;
  235.         End;
  236.         ClearEvent(Event);
  237.       End;
  238.   End;
  239.  
  240.   Procedure MyApp.NewWindow;
  241.   Var
  242.     Window:PMyWindow;
  243.     R: TRect;
  244.   Begin
  245.     R.Assign(0, 0, 24, 7);
  246.     R.Move(Random(55), Random(16));
  247.     Window := New(PMyWindow, Init(R, 'Demo Window', 1));
  248.     DeskTop^.Insert(Window);
  249.   End;
  250.  
  251.   { ** MyDeskTop **}
  252.   Constructor TMyDeskTop.Load(Var S: TBufStream);
  253.   Begin
  254.     TDeskTop.Load(S);
  255.     GetSubViewPtr(S,Windw);
  256.   End;
  257.  
  258.   Procedure TMyDeskTop.Store(Var S: TBufStream);
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Turbo Pascal                           NUMBER  :  676
  273.   VERSION  :  6.0
  274.        OS  :  MS/PC DOS
  275.      DATE  :  February 28, 1992                        PAGE  :  5/5
  276.  
  277.     TITLE  :  Desktop Save State Using Streams
  278.  
  279.  
  280.  
  281.  
  282.   Begin
  283.     TDeskTop.Store(S);
  284.     PutSubViewPtr(S,Windw);
  285.   End;
  286.  
  287.   { ** MyWindow **}
  288.   Constructor TMyWindow.Init(Bounds: TRect; WinTitle: String;
  289.   WindowNo: Word);
  290.   Begin
  291.     TWindow.init(Bounds,WinTitle,WindowNo);
  292.   End;
  293.  
  294.   { Main Program }
  295.   Var
  296.     MyTApp:MyApp;
  297.  
  298.   Begin
  299.     MyTApp.Init;
  300.     MyTApp.Run;
  301.     MyTApp.Done;
  302.   End.
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.